<template>
	<view class="lookpro" @tap="searchPro">
		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="icon-search"></text>
				<input :adjust-position="false" type="text" :placeholder="placeholder" @confirm="$emit('search', key)" confirm-type="search" v-model="key"></input>
			</view>
			<view class="action" v-if="!button">
				<button class="cu-btn bg-red shadow-blur round" @tap="$emit('search', key)">搜索</button>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapGetters } from 'vuex'
	export default {
		props: {
			is_search: {
				type: Boolean,
				default: false
			},
			placeholder: {
				type: String,
				default: '搜索产品'
			},
			button: {
				type: Boolean,
				default: false
			}
		},
		data () {
			return {
				key: ''
			}
		},
		computed: {
			...mapGetters(['shop'])
		},
		methods: {
			searchPro () {
				if (this.is_search) {
					if (this.shop.type === 1) {
						uni.navigateTo({
							url: '/shop/shop_list?type=1',
							success: () => {
								uni.hideKeyboard()
							}
						})						
					} else if (this.shop.type === 5) {
						uni.navigateTo({
							url: '/pages/search/productlist',
							success: () => {
								uni.hideKeyboard()
							}
						})						
					}
				}
			}
		}
	}
</script>

<style lang="less" scoped>
</style>